<!DOCTYPE html>
<HTML>
<HEAD><meta name="viewport" content="width=device-width, initial-scale=1">
<Title>BaseChart.makeSession</Title>
<link type='text/css' rel='Stylesheet' href="maxchartapi.css" />
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<p class="heading0">ChartDirector 7.0 (Java Edition)</p>
<p class="heading1"><a href="BaseChart.htm">BaseChart</a>.<wbr>makeSession</p>
<hr class="separator">
<p class="heading2a">Usage</p>
<div class="content">
public String makeSession(HttpServletRequest request, string name [, int imageFormat [, String filename [, boolean asAttachment ]]])
</div>
<p class="heading2">Description</p>
<div class="content">
Generates the chart as an image, saves it to a session variable and returns query parameters for loading the image.<br><br>
<div class="greyblock">
<b><span style='color:red'>Note:</span></b> This method is designed to address the limitation of older HTML standard that only allows the &lt;IMG&gt; tag to contain the URL of an image, but the image itself. The browser, after receiving the HTML, will need to connect to the URL with a separate HTTP connection to get the image.<br><br>
The HTML was designed that way because when the web was invented, people were still using 2400 bps modem. Loading an image could be very slow, and the network connection was charged on a per minute basis. It was better to see the text first, and load the image later via separate connections. Earlier browsers even allowed users to disable loading images entirely.<br><br>
Nowadays all browsers support embedding the images in HTML. Network speed is much faster that viewing video is common. Newer ChartDirector sample code no longer use this API.
</div><br>
The makeSession method is designed to support web applications in which the chart is generated in the same script that generates the HTML.<br><br>
Older HTML standard that only allows the the &lt;IMG&gt; tag to contain the URL of an image, but the image itself. The browser, after receiving the HTML, will need to use a separate HTTP connection to get the image. That means the script that generates the HTML with the chart image cannot put the chart image in the web page. One way is to save the chart image as a file using a unique filename, and then include the url of that image file in the &lt;IMG&gt; tag. This would create many files on the server and another mechanism is needed to clean up old files.<br><br>
The makeSession method saves the image in a session variable, avoiding creating image files on the hard disk. Almost all web servers today support session variables. The server will destroy the session variable when the user session ends, usually after a period of no activity.<br><br>
The makeSession method returns query parameters to allow the image to be loaded with the ChartDirector utility script "getchart.jsp".<br><br>
In a typical application, the chart is created like:<br><br>
<div class="codeblock"><code class='pre'>String chart1URL = c.makeSession(request, "chart1");</code></div><br>
The web page then includes an &lt;IMG&gt; tag as follows:<br><br>
<div class="codeblock"><code class='pre'>&lt;img src='&lt;%=response.encodeURL("getchart.jsp?"+chart1URL)%&gt;'&gt;</code></div><br>
Note that the above assumes "getchart.jsp" is in the same directory as your script. If it is in a different directory, you would need to modify the path in the &lt;IMG&gt; tag. Also, the directory that contains "getchart.jsp" must be in the same web application (servlet context) as your script, otherwise "getchart.jsp" will be unable to access the session variables created by your script.<br><br>
As an alternative to "getchart.jsp", ChartDirector also has a <a href="GetSessionImage.htm">GetSessionImage</a> servlet that performs the same function. This is useful for servlet applications that do not use JSP.<br><br>
For example, if you have mapped "*.chart" to GetSessionImage, you may use "getchart.chart" as the URL instead of "getchart.jsp". Please refer to the <a href="install.htm">Installation</a> section for details.<br><br>
<b>Note:</b> The getimage.jsp may not work properly in some very old web servers. In this case, the getimage.jsp will automatically redirect itself to the GetSessionImage servlet. Therefore, it may be useful to install the GetSessionImage servlet even if you may not need it.<br><br>
On the browser side, if the user attempts to save the image, such as by right clicking on the image and select "Save Image As" or something similar, the browser by default should derived a filename from the image URL. When makeSession is used, the URL is that of the script file "getchart.jsp". Using this as the filename of the image may not be desirable. In this case, the <b>filename</b> argument can be used to suggest an alternative filename to the browser.<br><br>
When the image is sent to the browser, HTTP allows it to be marked as an attachment. In this case, if the receiving HTML element is an &lt;IFRAME&gt;, &lt;FRAME&gt; or the browser window itself, the browser should save it as a file instead of displaying it. Some browsers may prompt the user for the directory to use, while others may save it to a special "download directory" without prompting the user. The <b>asAttachment</b> argument can be used to mark the image as an attachment.
</div>
<p class="heading2">Arguments</p>
<div class="content">
<div style="width:100%;box-sizing:border-box;">
<table border="1" cellpadding="5" cellspacing="0" width="100%"> 
<tr>
<th width="19%">Argument</th><th width="19%">Default</th><th>Description</th>
</tr>
<tr>
<td>request</td><td>(Mandatory)</td><td>The HttpServletRequest object representing the current request.</td></tr><tr><td>name</td><td>(Mandatory)</td><td>The name of the session variable used to store the chart image. If there are multiple chart images in the same web page, each image must use a different name.</td></tr><tr><td>imageFormat</td><td><a href="Chart.PNG.htm">PNG</a></td><td>A constant representing the format of the image. Must be one of the predefined constants <a href="Chart.PNG.htm">PNG</a>, <a href="Chart.JPG.htm">JPG</a>, <a href="Chart.GIF.htm">GIF</a>, <a href="Chart.BMP.htm">BMP</a>, <a href="Chart.WMP.htm">WMP</a>, <a href="Chart.SVG.htm">SVG</a>, <a href="Chart.SVGZ.htm">SVGZ</a> or <a href="Chart.PDF.htm">PDF</a>.</td></tr><tr><td>filename</td><td>""</td><td>The suggested filename to use when user saves the chart image as a file on the browser side.</td></tr><tr><td>asAttachment</td><td>false</td><td>Specifies whether the image is intended as an attachment.</td>
</tr>
</table>
</div>
</div>
<p class="heading2">Return Value</p>
<div class="content">
A string representing the query parameters for retrieving the image using "getchart.jsp" or the <a href="GetSessionImage.htm">GetSessionImage</a> servlet.
</div>
<br><hr class="separator">
<div class="copyright">&copy; 2022 Advanced Software Engineering Limited. All rights reserved.</div>
</body>
</HTML>
